import { Model } from '@vuex-orm/core';

export default class Config extends Model {
    // This is the name used as module name of the Vuex Store.
    static entity = 'config';

    // List of all fields (schema) of the post model. `this.attr` is used
    // for the generic field type. The argument is the default value.
    static fields() {
        return {
            id: this.number(null),
            name:this.string(''),
            pid:this.number(''),
            key: this.string(''),
            value: this.string(''),
            component: this.string(''),
            status: this.attr(''),
            created_ar: this.attr(''),
            updated_at: this.attr(''),
            deleted_at: this.attr(''),
            creator_id: this.attr(''),
        };
    }

    static fetchBy(params) {
        return this.api().get(`/config`,{params: params, persistBy: 'create' });
    }

    /**
     * save data to server DB
     */
    static async sync (data) {
        let result = await this.api().post(`/config`,data,{save:false});
        console.log(result.response.data);
        if(result.response.data.code == 10000){
            console.log(result.response.data);
        }else{
            console.log(result.response.data.message);
        }
        return result;
    }
}
